package com.buaa.airticketbookingsystem.Controller;

import com.buaa.airticketbookingsystem.Service.FavouriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
public class CancelFavoriteController {
    @Autowired
    private FavouriteService favouriteService;

    @PostMapping("/cancelFavorite")
    public Map<String, Object> cancelFavorite(@RequestBody Map<String, String> remap){
        String email = remap.get("email");
        String f_id = remap.get("f_id");
        System.out.println(email);
        System.out.println(f_id);
        Map<String, Object> resMap = new HashMap<>();
        try{
            favouriteService.delFavouriteRecords(email, f_id);
            resMap.put("res", true);
            resMap.put("message", "删除收藏成功");
        } catch(Exception e){
            e.printStackTrace();
            resMap.put("res", false);
            resMap.put("message", "抛出异常");
        }
        return resMap;
    }
}
